<template>
    <table border="1">
        <tr>
            <td>房型</td>
            <td>
                <select v-model="info.htid">
                    <option value="">--请选择--</option>
                    <option v-for="item in bind" :value="item.htid">{{item.htname}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>房间号码</td>
            <td>
                <input type="text" v-model="info.number">
            </td>
        </tr>
        <tr>
            <td>房号描述</td>
            <td>
                <input type="text" v-model="info.hnprescribe">
            </td>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <input type="radio" :value="true" name="B" v-model="info.hnstate">上架
                <input type="radio" :value="false" name="B" v-model="info.hnstate">下架
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <input type="button"  value="保存" @click="upd">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">

import {ref} from 'vue'
import { onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import { useRoute } from 'vue-router';
onMounted(()=>{
    fen();
})
const ror=useRouter();
const r=useRoute();
const bind=ref([{
    "htid": 0,
    "htname": "",
}])
const fen=()=>{
    axios.get('http://localhost:46564/api/House/Bind_t')
    .then(res=>{
        bind.value=res.data
    })
    .catch(error=>{
        console.log(error);
    })
}
const info=ref({
  "htid": "",
  "number": "",
  "hnprescribe": "",
  "hnstate": true,
  "nisdel": 0
})
const upd=()=>{
    if(info.value.htid==""){
        alert('房型不能为空');
        return;
    }
    if(info.value.number==""){
        alert('房间号码不能为空');
        return;
    }
    if(info.value.hnprescribe==""){
        alert('房号描述不能为空');
        return;
    }
    axios.post('http://localhost:46564/api/House/AddNum',info.value)
    .then(res=>{
        if(res.data>0){
            alert('保存成功');
            ror.push('/ShowNum');
        }
        else if(res.data==-1){
            alert('房间号不能重复');
            return;
        }
        else{
            alert('保存失败');
        }
    })
    .catch(error=>{
        console.log(error);
    })
}
</script>